//
//  MyWalletViewController.m
//  dangdang
//
//  Created by air on 16/1/26.
//  Copyright © 2016年 luweijie. All rights reserved.
//

#import "MyWalletViewController.h"
#import "RechargeViewController.h"
#import "BillDetailsViewController.h"
#import "TransactionDetailTableViewController.h"
#import "ExpenditureDetailTableViewController.h"
#import "RechargeRecordTableViewController.h"
#import "RefundRecordTableViewController.h"

@interface MyWalletViewController ()

@end

@implementation MyWalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self connection];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"账单明细" style:UIBarButtonItemStylePlain target:self action:@selector(billCheck)];
    
    self.title = @"我的钱包";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)connection{
    NSString * uid = userObject.userID;
    NSString * token = userObject.accessToken;
//    NSNumber * number = [NSNumber numberWithInt:10];
    
    if(uid)
    {
        NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
        [params setObject:uid forKey:@"uid"];
        [params setObject:token forKey:@"token"];
        
        [self postRequestWithMethodName:@"user/get_balance" andParams:params andSender:nil];
        [LoadingView showInView:self.view image:nil info:@"通讯中，请稍候..." animated:YES modeled:YES autoHide:NO];
    }
}

- (void)billCheck{
    BillDetailsViewController *pageController = [[BillDetailsViewController alloc] init];
    NSArray *viewControllerClasses = @[[TransactionDetailTableViewController class], [ExpenditureDetailTableViewController class], [RechargeRecordTableViewController class], [RefundRecordTableViewController class]];
    NSArray *titles = @[@"收入明细", @"支出明细", @"充值记录", @"退款记录"];
    pageController.viewControllerClasses = viewControllerClasses;
    pageController.titles = titles;
    pageController.menuItemWidth = self.view.frame.size.width / 4;
    pageController.menuViewStyle = WMMenuViewStyleLine;
    pageController.titleSizeSelected = 15.0;
    pageController.titleName = @"交易明细";
    
    dispatch_async(dispatch_get_main_queue(), ^{
        UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:pageController];
        [self presentViewController:navi animated:YES completion:nil];
    });
    
//    [self.navigationController pushViewController:pageController animated:YES];
}

- (IBAction)rechargeButton:(UIButton *)sender {
    RechargeViewController * rechargeboardVC = [[UIStoryboard storyboardWithName:@"RechargeViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"RechargeViewController"];
    [self.navigationController pushViewController:rechargeboardVC animated:YES];
}

//网络连接返回数据
- (void)requestSuccessedWithResult:(id)result NSURLSessionTask:(NSURLSessionTask *)task sender:(id)sender{
    
    if ([result isKindOfClass:[NSDictionary class]]) {
        NSString * code = [NSString stringWithFormat:@"%@", [result objectForKey:@"retcode"]];
        if ([code isEqualToString:@"0"]){
            _balanceLabel.text = [NSString stringWithFormat:@"￥%@", [result objectForKey:@"retmsg"]];
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
